package com.guoxin.concurrentprogramming.chapter1;

public class ThreadVisibility extends Thread {

    public volatile boolean flag = true;

    @Override
    public void run() {
        System.out.println("子线程开始");
        while (flag){
        }
        System.out.println("子线程结束");
    }

    public static void main(String[] args) throws InterruptedException {
        ThreadVisibility t = new ThreadVisibility();
        t.start();
        Thread.sleep(2000);
        t.flag = false;

    }
}
